在 YAML 文件中用 number_sections: TRUE 参数设置自动编号:
可以用 html 中的 <br> 标签来插入换行符。
A first sentence
A seconde sentence
同样可以用 html 代码居中图片
有时候 R 代码生成的图片周围有太多空白,这时可以用 fig.asp 参数来调整
library(png)
library(grid)
img <- readPNG("Snipaste_2020-03-04_20-36-21.png")
grid.raster(img)
添加 footer 和 header 我们也可以在文档的开头或结尾添加一些 html 代码
在标题前加上空行 除了在每个标题前加上 <br> 外,更方便的办法是直接在 .css 文件中添加样式。创建一个 style.css 文件
A title will follow, but with a lot of space before it
content of part 1
content of part 2
可以在代码块的 header 中添加图注
library(tidyverse)
mpg %>%
ggplot( aes(x=reorder(class, hwy), y=hwy, fill=class)) +
geom_boxplot() +
xlab("class") +
theme(legend.position="none")
Figure: Here is a really important caption.
在 R Markdown 中可以用 LaTeX 语法插入数学公式,用 $ 分隔 Latex 语法:
$A = (r^{4}) / $
并排放两张图
boxplot(1:10)
plot(rnorm(10))
为子标题实现选项卡切换的效果
第二步 - 用链接指向该锚点:
For example, this link will bring …
交互式图表
library(ggplot2)
library(plotly)
library(gapminder)
p <- gapminder %>%
filter(year==1977) %>%
ggplot( aes(gdpPercap, lifeExp, size = pop, color=continent)) +
geom_point() +
scale_x_log10() +
theme_bw()
ggplotly(p)
A work by Yan Holtz
Yan.holtz.data@gmail.com